// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    //wx.setStorageSync('logs', logs)

    wx.getLocation({
      type: "wgs84",
      success (res) {
          console.log(res)
      }
    }),


    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        console.log(res.code)
        console.log(this.globalData.baseUrl)
        let that = this;
        wx.request({
          url: this.globalData.baseUrl+'wxmn/getUserInfo',
          //默认get请求，参数会拼接到参数请求后面
          data: {
            code: res.code,
            msg: '获取用户openid'
          },
          success(res) {
            if(res.data.code=="0000"){
              let rspDate = res.data.data;
              console.log("返回的信息",rspDate)
              //记录数据
           
              that.globalData.userInfo = rspDate;
              wx.setStorageSync("userId",rspDate.openid);
              console.log("userInfo",that.globalData.userInfo)

            }
            
          },
          fail(res){
            console.log("fail for ",res)
            wx.showModal({
              title: '提示',
              content: '请求失败'+res.errMsg,
              success(res) {
                if (res.confirm) {
                  console.log('用户点击确定')
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })
          }
        })

      }
    })
  },


  globalData: {
    userInfo: null,
    baseUrl: "https://www.butsowhat.cn/"
    // baseUrl: "https://127.0.0.1:8443/Future/"
    // baseUrl: "https://111.229.191.103:8443/Future/"
  }
})
